const app = getApp();
Page({
  data: {
    pageCount: '',
    pageno: 1,
    renderObj: {
      listArr: []
    },
    tabsName: [],
    currentidx: 0,
    chooseFlag: true,
    picServer: app.globalData.picServer,
    currentTab:0,
    addName: wx.getStorageSync("addName")
  },
  onLoad: function () {
    this.initPage();
  },
  onShow: function () {
    this.getContent()
  },
  initPage: function () {
    var _this = this;
    var userid = app.globalData.userid;
    this.getContent();
    app.doReq(app.globalData.DICTIONARY, { "parentId": 952 }, 'get', function (res) {
      var data = res.data;
      var list = data.obj['952'];
      if (data.code == 200) {
        _this.setData({
          tabsName: list,
        })
      }
    });
  },
  getContent: function () {
    wx.showLoading({
      title: '加载中',
    })
    var userid = app.globalData.userid;
    var _this = this;
    app.doReq(app.globalData.SERVICE.ACTIVITY.LIST, {
      id: userid,
      "blind.theme.id": _this.data.currentTab == 0 ? "" : _this.data.currentTab,
      pageno: _this.data.pageno,
      pagesize: 10,
      code:wx.getStorageSync("addCode"),
    }, 'get', function (res) {
      wx.hideLoading();
      if (_this.data.pageno == 1) {
        _this.setData({
          renderObj: {
            listArr: res.data.pageitems,
          },
          pageCount: res.data.pagecount
        })
      } else {
        _this.setData({
          renderObj: {
            listArr: _this.data.renderObj.listArr.concat(res.data.pageitems)
          }
        })
      }
    });
  },
  whentapNavi: function (e) {
    var _this = this;
    _this.data.pageCount= '';
      _this.data.pageno= 1;
    let id = e.currentTarget.dataset.id;
    _this.data.currentTab=id;
    //记录上次点击的对象的序号
    var oldidx = this.data.currentidx;
    //记录当前点击的对象的序号
    var currentidx = e.currentTarget.dataset.idx;
    if (oldidx == currentidx) {
      var chooseFlag = this.data.chooseFlag;
      _this.setData({
        currentidx: currentidx,
        chooseFlag: !chooseFlag
      });
    } else {
      _this.setData({
        currentidx: currentidx,
        chooseFlag: true
      });
    }
    _this.getContent();
  },
  onReachBottom: function () {//刷新
    console.log("xialale")
    var _this = this;

    var currentPageNo = _this.data.pageno;
    if (currentPageNo <= _this.data.pageCount) {
      _this.data.pageno++;
      _this.getContent();
    }
  },
  goChooseCityPage: function () {
    wx.navigateTo({
      url: '../../pages/chooseCity/chooseCity'
    })
  },
    activityDetails: function (e) {
    var typeid = e.currentTarget.dataset.typeid;
    wx.navigateTo({
      url: '../../pages/activityDetails/activityDetails?typeid=' + typeid
    });
  },
});